export const getInputs = () => [
	['11', '1'],
	['1010', '1011'],
];

/**
 * **[67. 二进制求和](https://leetcode.cn/problems/add-binary/)**
 *
 * 给你两个二进制字符串 `a` 和 `b` ，以二进制字符串的形式返回它们的和。
 *
 * @param a
 * @param b
 * @returns
 */
export default function (a: string, b: string): string {
	let result = '';

	const aLen = a.length,
		bLen = b.length;
	const maxLength = Math.max(aLen, bLen);
	let index = 1;

	let flag: '0' | '1' = '0';
	while (index <= maxLength) {
		const aItem = a[aLen - index] || '0',
			bItem = b[bLen - index] || '0';
		let item: '0' | '1';
		if (aItem === bItem) {
			item = '0';
			if (flag !== item) item = '1';

			if (aItem === '1') flag = '1';
			else flag = '0';
		} else {
			item = '1';
			if (flag === item) item = '0';
			else flag = '0';
		}

		result = `${item}${result}`;
		index++;
	}

	if (flag === '1') return `1${result}`;

	return result;
}
